import request from '@/utils/request'

export function refreshQuantity(compilationId) {
  return request({
    url: '/note/note/refreshQuantity?compilationId=' + compilationId,
    method: 'get'
  })
}

/**
 * 获取一个题
 * @param compilationId
 * @returns {*}
 */
export function getRemainingQuantity(compilationId) {
  return request({
    url: '/note/note/getRemainingQuantity?compilationId=' + compilationId,
    method: 'get'
  })
}

export function compareSimilarDegree(data) {
  return request({
    url: '/note/note/compareSimilarDegree',
    method: 'post',
    data: data
  })
}

// 查询笔记列表
export function listNote(query) {
  return request({
    url: '/note/note/list',
    method: 'get',
    params: query
  })
}

// 查询笔记详细
export function getNote(id) {
  return request({
    url: '/note/note/' + id,
    method: 'get'
  })
}

// 新增笔记
export function addNote(data) {
  return request({
    url: '/note/note',
    method: 'post',
    data: data
  })
}

// 修改笔记
export function updateNote(data) {
  return request({
    url: '/note/note',
    method: 'put',
    data: data
  })
}

// 删除笔记
export function delNote(id) {
  return request({
    url: '/note/note/' + id,
    method: 'delete'
  })
}

// 列表树
export function getTreeList() {
  return request({
    url: '/note/tree/getTreeList/',
    method: 'post'
  })
}

// 随机获取一个
export function randomOne(compilationId) {
  return request({
    url: '/note/note/randomOne?compilationId=' + compilationId,
    method: 'get'
  })
}

// 随机获取一个
export function notShowAgain(id) {
  return request({
    url: '/note/note/notShowAgain/' + id,
    method: 'get'
  })
}

/**
 * 将数字转成中文大写
 * @params num
 */
export function toChinesNum(num) {
  let changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']; //changeNum[0] = "零"
  let unit = ["", "十", "百", "千", "万"];
  num = parseInt(num);
  let getWan = (temp) => {
    let strArr = temp.toString().split("").reverse();
    let newNum = "";
    for (var i = 0; i < strArr.length; i++) {
      newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
    }
    return newNum;
  }
  let overWan = Math.floor(num / 10000);
  let noWan = num % 10000;
  if (noWan.toString().length < 4) noWan = "0" + noWan;
  return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
}

